# @Time : 2020/12/10 10:55
# @Author: sl
# @File : user_query_page.py
import logging

from flask import request

from app.v2.models.UserModel import UserSample
from framework.api.AbstractApi import AbstractApi
from framework import db
from framework.vo.PageObject import PageObject


# get list page对象 请求示例 http://127.0.0.1:8181/v2/userQueryPage?page_size=3&page_index=1
class UserQueryPage(AbstractApi, PageObject):
    def handle_get_request(self):
        logging.info("至少需要要跳转的页数，每页多少显示条数")
        self.__dict__.update(request.args)  # 需要处理类型
        res = db.session.query(UserSample).filter().paginate(int(self.page_index), int(self.page_size))#fileter中查询条件UserSample.name == 'spongebob'
        resDict = {'total': res.total, 'items': res.items}
        return resDict
